@extends('common.admin_template')

@section('content')
    <div class="boxWidth">
        @include('common.notice_msg')
        <?php $shop = isset($_GET["shop"])?$_GET["shop"]:''; ?>
        <div class="row">
            <div class="col-xs-4 boxPaddingLeft">
                <div class="addFormItemHead">添加新商品分类</div>
                <form method="post" action="{{url('admin/cats/save')}}">
                <input type="hidden" name="_token" value="{{ csrf_token() }}">
                <div class="addInput row">
                    <div class="col-xs-3">商铺名称</div>
                    <div class="col-xs-9">
                        @if($shop)
                            {{$Shops->name}}
                            <input type="text" name="Cat[parent_id]" style="display: none" value="{{$Shops->id}}">
                        @else
                            <select name="Cat[parent_id]">
                                @foreach($Shops as $s)
                                    <option value="{{$s->id}}">{{$s->name}}</option>
                                @endforeach
                            </select>
                        @endif
                    </div>
                </div>
                <div class="addInput" id="TagNameBox">
                    <div class="addInputText">分类名称</div>
                    <input type="text" class="form-control" id="TagName" name="Cat[name]" placeholder="请输入商品分类名称">
                </div>
                <div class="addInput">
                    <div class="addInputText">分类排序</div>
                    <input type="text" class="form-control" name="Cat[order_id]" placeholder="不填则自动生成排序"/>
                </div>
                <div class="addInput row">
                    <div class="col-xs-6"><button class="btn btn-primary addInputBtn" type="submit" id="formSubmit">添加新商品分类</button></div>
                </div>
                </form>
            </div>
            <div class="col-xs-8 boxPaddingRight">
                <table class="table table-hover adminTableBg">
                    <thead>
                    <tr>
                        <th class="col-xs-2">ID</th>
                        <th class="col-xs-3">分类名</th>
                        <th class="col-xs-3">店铺名</th>
                        <th class="col-xs-2">排序</th>
                        <th class="col-xs-2">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($Cats as $item)
                    <tr>
                        <th class="col-xs-2 itemTd">{{$item->id}}</th>
                        <th class="col-xs-3">{{$item->name}}</th>
                        <th class="col-xs-3">{{$item->shop}}</th>
                        <th class="col-xs-2 itemTd">{{$item->order_id}}</th>
                        <th class="col-xs-2 itemTd">
                            <a href="{{url('admin/cats/edit',['id' => $item->id])}}"><span id="addInput">修改</span></a>
                            <a href="{{url('admin/cats/del',['id' => $item->id])}}"><span class="redColor" id="delInput" onclick="if(!confirm('是否确认删除？'))return false">删除</span></a>
                        </th>
                    </tr>
                    @endforeach
                    </tbody>
                </table>
                <div class="pull-right">
                    <?php
                    if($shop){
                        $url = ['shop' => $shop];
                    }else{
                        $url = [];
                    }
                    ?>
                    {!! $Cats->appends($url)->render() !!}
                </div>
            </div>
        </div>
    </div>
@stop
@section('js')
    <script>
        (function () {
            $('#formSubmit').on('click',function (e) {
                if(!$('#TagName').val().replace(/(^\s*)|(\s*$)/g, "")){
                    $('#TagNameBox').addClass('has-error');
                    e.preventDefault();
                }
            });
        })();
    </script>
@stop